package cn.dinkevin.xui.activity;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import com.readystatesoftware.systembartint.SystemBarTintManager;

import cn.dinkevin.xui.R;


/**
 * 浸透式 Activity
 * Created by ChengPengFei on 2016/11/22 0022.</br>
 * Copyright ©2017 juziwl, All Rights Reserved.
 */

public abstract class AaturateActivity extends AbstractActivity {

    /**
     * 第三方的系统 bar 管理
     */
    protected SystemBarTintManager systemBarTintManager;

    @Override
    protected void onCreate(Bundle savedInstance) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstance);

        // 设置沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true);
        }
        systemBarTintManager = new SystemBarTintManager(this);
        systemBarTintManager.setStatusBarTintEnabled(true);

        systemBarTintManager.setStatusBarTintResource(R.color.xui_head_background);
    }

    /**
     * 设置状态栏透明度
     * @param alpha 透明度
     */
    protected void setStatusBarAlpha(float alpha){
        systemBarTintManager.setStatusBarAlpha(alpha);
    }

    /**
     * 设置状态栏透明
     * @param on
     */
    @TargetApi(Build.VERSION_CODES.KITKAT)
    protected void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }
}
